package beans;

import utils.GetBeanUtil;
import utils.UpdateUtil;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import java.io.IOException;

@ManagedBean(name = "navigationBean")
@SessionScoped
public class NavigationBean {
    private static final String PATH = "/templates/pages/";
    private String page;

    @PostConstruct
    public void init() {
        page = PATH + "main.xhtml";
    }

    public String getPage() {
        return page;
    }

    public void setPage(String page) {
        this.page = page;
    }

    public void action(String s) throws IOException {
        page = PATH + s;
        UpdateUtil.updatePage();
    }

    public void redirect() throws IOException{
        DocumentsBean documentsBean = (DocumentsBean) GetBeanUtil.getBean("documentsBean");
        FacesContext.getCurrentInstance().getExternalContext().redirect(documentsBean.getDocument().getLink());
    }

}
